<?php

/**
 * @category   MM
 * @package    MM_Service
 */
class MM_Service_Admin_EventContent extends Mediad2_Service_Abstract
{
	/**
	 * 初始化
	 */
	public function init()
	{
		$this->setMapper('MM_Mapper_EventContent');
		$this->setModel('MM_Model_EventContent');
	}
	
	/**
	 * 更新活动内容
	 * @param int $ecid
	 * @param array $params
	 * @return Mediad2_Model_Result
	 */
	public function updateContent($ecid, array $params)
	{
		try {
			//获取指定id的event content
			$result = $this->find($ecid);
			if ($result->getCode()==$result::CODE_FAILURE) return $result;
				
			//封装model
			$model = $result->getData();
			if (isset($params['ectype'])) $model->setEctype($params['ectype']);
			if (isset($params['esid'])) $model->setEsid($params['esid']);
			if (isset($params['title'])) $model->setTitle($params['title']);
			if (isset($params['content'])) $model->setContent($params['content']);
			if (isset($params['url'])) $model->setUrl($params['url']);
			if (isset($params['num'])) $model->setNum($params['num']);
			if (isset($params['status'])) $model->setStatus($params['status']);
			if (isset($params['attachment'])) $model->setAttachment($params['attachment']);
			if (isset($params['canuse'])) $model->setCanuse($params['canuse']);
			if (isset($params['fid'])) $model->setFid($params['fid']);
			if (isset($params['filepath'])) $model->setFilepath($params['filepath']);
						
			$model->setAddtime(time());	
			return $this->update($model);
	
		} catch (Zend_Exception $e) {
			$this->handleException($e); //出错处理
			return $this->returnResult(Mediad2_Model_Result::CODE_FAILURE); //返回结果--失败
		}
	}
	
	/**
	 * 获得Event Content Type
	 */
	public function getEventContentType()
	{
		try {
			$dictUtil = Mediad2_Service_Util_Dict::getInstance();
			$result = $dictUtil->getId('ectype');
			return $this->returnResult(Mediad2_Model_Result::CODE_SUCCESS,null,$result);
		} catch(Zend_Exception $e) {
			$this->handleException($e); //出错处理
			return $this->returnResult(Mediad2_Model_Result::CODE_FAILURE);	//返回结果--失败
		}	
	}
	
}